import {UserActions} from './user';

const initialState = {
  items: [],
  messages: [],
};

export const OrderActions = {
  UPDATE_ORDER: 'update_order',
  RESET_ORDER: 'reset_order',
};

export function updateOrder(payload) {
  return {
    type: OrderActions.UPDATE_ORDER,
    payload,
  };
}

export function resetOrder() {
  return {
    type: OrderActions.RESET_ORDER,
  };
}

export default function order(state = initialState, action) {
  switch (action.type) {
    case OrderActions.UPDATE_ORDER:
      return {...state, ...action.payload};
    case OrderActions.RESET_ORDER:
      return {
        items: [],
        messages: [],
      };
    case UserActions.USER_SIGN_OUT:
      return {
        items: [],
        messages: [],
      };
    default:
      return state;
  }
}
